<template>
  <div class="home">
    <el-table :data="data" border stripe>
      <el-table-column
        width="50"
        label="序号"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column
        label="学生ID"
        prop="studentId"
        align="center"
      ></el-table-column>
      <el-table-column
        label="调入房间"
        prop="toDorm"
        align="center"
      ></el-table-column>
      <el-table-column
        label="申请时间"
        prop="applyTime"
        align="center"
      ></el-table-column>
      <el-table-column
        label="状态"
        prop="state"
        align="center"
      ></el-table-column>
      <el-table-column width="300px" label="操作" align="center">
        <template v-slot="scope">
          <el-button @click="toEdit" type="primary">查看</el-button>
          <a-modal
            v-model:visible="visible"
            @ok="handleOk()"
            @cancel="handleCancel"
          >
            <template #title>调宿理由</template>
            <div>理由: {{ scope.row.reason }}</div>
          </a-modal>
          <el-button @click="toAgree(scope.row)" type="primary"
            >同意
          </el-button>
          <el-button @click="refuse(scope.row.id)" type="danger"
            >不同意
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import {
  Apply,
  ApplyControllerService,
  User,
  UserControllerService,
  UserRegister,
} from "../../../generated";
import { isNumber } from "@arco-design/web-vue/es/_utils/is";

const dialogForm = ref(true);

const show = ref(true);

const data = ref([]);
const initSearchParams = {
  pageSize: 10,
  pageNum: 1,
};
const loadData = (params: any) => {
  ApplyControllerService.getApplyListUsingPost(1, 5).then((res: any) => {
    data.value = res.data.records;
  });
};
const form = reactive({
  applyTime: "",
  id: undefined,
  reason: "",
  state: "",
  studentId: undefined,
  toDorm: "",
} as Apply);

const searchParams = ref(initSearchParams);
loadData(initSearchParams);

const visible = ref(false);
const toEdit = () => {
  visible.value = true;
};
const refuse = (row: any) => {
  form.id = row;
  ApplyControllerService.refuseUsingPost(form);
  loadData(initSearchParams);
};
const toAgree = (row: any) => {
  form.id = row.id;
  form.toDorm = row.toDorm;
  ApplyControllerService.agreeUsingPost(form);
  loadData(initSearchParams);
};
// const handleOk = () => {
//   UserControllerService.updateUserUsingPost(form);
// };
const handleOk = () => {
  visible.value = false;
};
const handleCancel = () => {
  visible.value = false;
};
</script>
